#include "stdafx.h"
#include "IModule.h"
#include "ModuleMgr.h"

IModule::IModule() :
	m_isinit(false),
	m_isexit(true),
	m_mgr(nullptr)
{
	Engine::Get().AddInputListener(this);
}

IModule::~IModule()
{
}

void IModule::init(const std::string &scenename)
{
	m_name = scenename;
	if ( DoInit() )
	{
		m_isinit = true;
		m_isexit = false;
	}
	else
		Log::Get().Err("Error module (%s) init", scenename.c_str());
}

bool IModule::frame()
{
	if ( !m_isinit || m_isexit )
		return false;
	else
		return DoRun();
}

void IModule::close()
{
	if ( m_isinit )
	{
		DoClose();
		m_isinit = false;
	}
}

void IModule::SetNextModule(const std::string &name)
{
	m_mgr->SetActiveModule(name);
}